package 代码记录.校招笔试真题.笔试真题_2023.博乐科技;

/**
 * @author zx
 * @create 2023-02-19 20:47
 */
public class Test4 {
    /**
     * @return 30%
     * 给定一个二维数组map和给出多个字符串，判断哪些字符串可以一个字母出发，~
     */
    public boolean[] checkStrInMap (String[][] map, String[] strArr) {
        boolean[] res = new boolean[strArr.length];
        for(int i = 0;i < strArr.length;i++){
            String str = strArr[i];
            res[i] = dfs(map,str);
        }
        return res;
    }
    private boolean dfs(String[][] map, String str){
        boolean res = true;
        int[][] arr = new int[str.length()][2];
        for(int k = 0;k < str.length();k++){
            boolean flag = false;
            for(int i = 0;i < map.length;i++){
                for(int j = 0;j < map[0].length;j++){
                    if(map[i][j].charAt(0) == str.charAt(k)){
                        arr[k][0] = i;
                        arr[k][1] = j;
                        flag = true;
                    }
                }
            }
            if(flag == false){
                return false;
            }
        }
        for(int i = 1;i < arr.length;i++){
            int a = arr[i][0];
            int b = arr[i][1];
            int x = arr[i - 1][0];
            int y = arr[i - 1][1];
            if(a == x && (b == y + 1 || b == y - 1)){
                res = true;
            }else if(b == y && (a == x + 1 || a == x - 1)){
                res = true;
            }else{
                res = false;
            }
        }
        return res;
    }
}
